<template>
    <div>
        <div style="">
            <ss15002-modal ref="ss15002Modal" @ok="reloadData"></ss15002-modal>
            <ss15012-modal ref="ss15012Modal" @ok="reloadData"></ss15012-modal>
        </div>
        <div style="margin-top: 10px">
            <Table :columns="columns" :data="tableData" :loading="Loading" border>
                <template slot-scope="{ row, index}" slot="action">
                    <Button type="success" size="small" style="margin-right: 5px" @click="handleEdit(index)">详情</Button>
                    <!--                    <Button type="info" size="small" style="margin-right: 5px" @click="handleDelete(index)">删除</Button>-->
                    <!--                    <Button type="success" size="small" style="margin-right: 5px" @click="handleView(index)">详情</Button>-->
                </template>
            </Table>
            <div style="margin: 10px;overflow: hidden">
                <div style="float: right;">
                    <Page :total="dataCount" :page-size="pageSize" show-total class="paging"
                          @on-change="handleTableChange"></Page>
                </div>
            </div>
        </div>
    </div>
</template>

<script>
    import ss15002Modal from './modules/Ss15002Modal.vue'
    import ss15012Modal from './modules/Ss15012Modal.vue'
    import {postAction} from '@/api/request'
    import {CommonMixin} from '@/views/common/js/CommonMixin'

    export default {
        name: 'application2',
        mixins: [CommonMixin],
        components: {
            ss15002Modal, ss15012Modal
        },
        data() {
            return {
                url: {
                    list: '/api/ac/subsistence/ss15002Service/getPageList',
                    getSs11002One: '/api/ac/subsistence/ss15002Service/getOne',
                    getss15012One: '/api/ac/subsistence/ss15012Service/getOne',
                    deleteSs11002: '/api/ac/subsistence/ss15002Service/deleteData',
                    deletess15012: '/api/ac/subsistence/ss15012Service/deleteData',
                    checkStep2: '/api/ac/subsistence/ss15002Service/checkPersonInfo',
                },
                dataCount: 0,
                pageSize: 10,
                familyInfo: {},
                queryParam: {},
                columns: [
                  {
                    title: '姓名',
                    key: 'azcp0003',
                    align: 'center',
                  },
                  {
                    title: '与申请人关系',
                    key: 'azcp0517_name',
                    align: 'center',
                    width: 130
                  },
                  {
                    title: '性别',
                    key: 'azcp0004_name',
                    align: 'center',
                  },
                  {
                    title: '证件号码',
                    key: 'azcp0001',
                    align: 'center',
                    width: 190
                  },
                  {
                    title: '民族',
                    key: 'azcp0007_name',
                    align: 'center',
                  },
                  {
                    title: '健康状况',
                    key: 'azcp0009_name',
                    align: 'center',
                    width: 120
                  },
                  {
                    title: '劳动能力丧失情况',
                    key: 'azcp0502_name',
                    align: 'center',
                    width: 170
                  },
                  {
                    title: '查验状态',
                    key: 'azcp0578_name',
                    align: 'center',
                  },
                  {
                    title: '保障状态',
                    key: 'type_name',
                    align: 'center',
                  },
                  {
                    title: '操作',
                    slot: 'action',
                    align: 'center',
                    fixed: 'right',
                  }
                ],
                tableData: [],
                Loading: false,
                btnLoading: false,
                ss11001Id: this.$parent.familyInfo.ss11001Id,
                ss11002Id: this.$parent.familyInfo.ss11002Id,
            }
        },
        methods: {
            prevStep() {
                this.$parent.clickStep(0);
            },
            nextStep() {
                this.$parent.clickStep(2);
            },
            handleEdit(index) {
                let that = this;
                let record = that.tableData[index];
                let url = null;
                let dataParam = {};
                dataParam.id = record.id;
                if (record.id) {
                    if (record.type == '1') {
                        url = that.url.getSs11002One
                        postAction(url, dataParam).then((res) => {
                            if (res.data.data.code == 1) {
                                res.data.data.data.ss12001Id = that.familyInfo.ss12001Id
                                that.$refs.ss15002Modal.edit(res.data.data.data)
                            } else {
                                that.$Message.error(res.data.data.msg);
                            }
                        });
                    } else {
                        url = that.url.getss15012One
                        postAction(url, dataParam).then((res) => {
                            if (res.data.data.code == 1) {
                                that.$refs.ss15012Modal.edit(res.data.data.data)
                            } else {
                                that.$Message.error(res.data.data.msg);
                            }
                        });
                    }
                } else {
                    that.$Message.error('请选择操作数据');
                }
            },
            createSs11002() { // 录入保障人员
                let that = this;
                that.$refs.ss15002Modal.ss11001Id = that.ss11001Id
                that.$refs.ss15002Modal.create()
            },
            createss15012() { // 录入非保障人员
                let that = this;
                that.$refs.ss15012Modal.ss11001Id = that.ss11001Id
                that.$refs.ss15012Modal.create()
            },
            handleDelete(index) {
                let that = this;
                let record = that.tableData[index];
                if (record.id) {
                    let isMaster = record.azcp0517;
                    if (isMaster == '01') {
                        that.$Message.error('家庭户主不可删除，如需删除请更新家庭户主再操作');
                        return
                    } else {
                        this.$Modal.confirm({
                            title: '确定删除吗',
                            onOk: () => {
                                let url = null;
                                let dataParam = {};
                                dataParam.id = record.id;
                                if (record.type == '1') {
                                    url = that.url.deleteSs11002
                                } else {
                                    url = that.url.deletess15012
                                }
                                postAction(url, dataParam).then((res) => {
                                    if (res.data.data.code == 1) {
                                        that.$Message.success(res.data.data.msg);
                                        that.reloadData();
                                    } else {
                                        that.$Message.error(res.data.data.msg);
                                    }
                                });
                            },
                            onCancel: () => {
                            }
                        });
                    }

                } else {
                    that.$Message.error('请选择操作数据');
                }
            },
            handleView() {
                this.$Message.warning('功能开发中');
            },
            reloadData() {
                let that = this;
                that.queryParam.azcp0500 = that.ss11001Id;
                that.loadData();
            },
        },
        created() {
            let that = this;
            that.familyInfo = that.$parent.familyInfo;
            that.queryParam.azcp0500 = that.familyInfo.ssca0001;
            //that.queryParam.azcp0500='ab77b34f1ecb4aa28b0e2b95c0db868d';
            this.loadData();
        },
    }
</script>

<style scoped>

</style>
